export default {
	namespaced: true,
	state: () => ({
		addressData: JSON.parse(uni.getStorageSync('addressData') || '{}'),
		token: uni.getStorageSync('token') || '',
		userinfo: JSON.parse(uni.getStorageSync('userInfo') || '{}'),
		redirectInfo: null,
	}),
	
	mutations: {
		updataAddressData(state, addressData) {
			state.addressData = addressData;
			this.commit('my_user/saveAddressDataToStorage');
		},
		
		saveAddressDataToStorage(state) {
			uni.setStorageSync('addressData', JSON.stringify(state.addressData));
		},
		
		updateUserInfo(state, userInfo) {
			state.userInfo = userInfo;
			this.commit('my_user/saveUserInfoToStorage');
			
		},
		
		saveUserInfoToStorage(state) {
			uni.setStorageSync('userInfo', JSON.stringify(state.userInfo));
		},
		
		updateToken(state, token) {
			state.token = token;
			console.log('userinfo', state.userInfo);
			this.commit('my_user/saveTokenToStorage');
		},
		
		saveTokenToStorage(state) {
		  uni.setStorageSync('token', state.token);
		},
		
		updateRedirectInfo(state, info) {
		  state.redirectInfo = info;
		},		
	},
	
	getters: {
		addressDataStr(state) {
			const { provinceName, cityName, countyName, detailInfo} = state.addressData;
			if(!provinceName)	return ''; 
			return provinceName + cityName + countyName + detailInfo;
		},
	},
}